#!/usr/bin/env python
    ##########################################################################
    ##(c) 2008 Bastian Damman                                               ##
    ##                                                                      ##
    ##This file is part of Kaboom-O-rama.                                   ##
    ##                                                                      ##
    ##Kaboom-O-rama is free software: you can redistribute it and/or modify ##
    ##it under the terms of the GNU General Public License as published by  ##
    ##the Free Software Foundation, either version 3 of the License, or     ##
    ##(at your option) any later version.                                   ##
    ##                                                                      ##
    ##Kaboom-O-rama is distributed in the hope that it will be useful,      ##
    ##but WITHOUT ANY WARRANTY; without even the implied warranty of        ##
    ##MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         ##
    ##GNU General Public License for more details.                          ##
    ##                                                                      ##
    ##You should have received a copy of the GNU General Public License     ##
    ##along with Kaboom-O-rama.  If not, see <http://www.gnu.org/licenses/>.##
    ##########################################################################
import pygame
from pygame import *
from Const import SCREENWIDTH, SCREENHEIGHT
from Level import Level
from Image.ImageLoader import ImageLoader

class Main:
    def __init__(self):
        pygame.init()
        mixer.init()
        font.init()
        self.font_fps = font.SysFont(font.get_default_font(), 16)
        self.fps = 0
        self.InitGame()
        self.Load()
        self.room = 0
        
    def InitGame(self):
        self.screenWidth = SCREENWIDTH
        self.screenHeight = SCREENHEIGHT
        
        self.screen = display.set_mode((self.screenWidth, self.screenHeight), SRCALPHA|HWSURFACE|HWACCEL, 0) #init screen + set alpha enabled

    def Load(self):
        self.il = ImageLoader()
        self.il.load()
        self.level = Level("Level2.txt", self.il, self.screen)
    
    def update(self, fps):
        events = event.get()
        for e in events:
            if e.type == QUIT:
                return 1
            elif e.type == KEYDOWN:
                if e.key == K_ESCAPE:
                    return 1
        self.level.update(events, fps)
        
        self.fps = fps
        return 0
                    
    def draw(self):
        self.screen.fill((0, 100, 150))
        self.level.draw()
        
        t = self.font_fps.render("fps: " + str(self.fps), True, (255, 255, 255))
        self.screen.blit(t, (16, 16))
        
        display.update()
